//
//  HeaderBankCardView.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/7.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "HeaderBankCardView.h"

@implementation HeaderBankCardView

- (instancetype)init {
    
    self = [super init];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        [self.bankCardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(self);
            make.height.mas_equalTo(self.bankCardImageView.mas_width).multipliedBy(261.f/504.f);
            make.top.mas_equalTo(self.mas_top).offset(15);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-15);
        }];
        [self.removeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self.bankCardImageView.mas_top);
            make.centerX.mas_equalTo(self.bankCardImageView.mas_right);
            make.size.mas_equalTo(CGSizeMake(22, 22));
        }];

        [self.cameraImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(60, 60));
            make.centerX.mas_equalTo(self.bankCardImageView);
            make.centerY.mas_equalTo(self.bankCardImageView.mas_centerY).offset(-18);
        }];
        [self.hintLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(self.bankCardImageView);
            make.top.mas_equalTo(self.cameraImageView.mas_bottom).offset(10);
        }];
        
        self.removeBtn.hidden = YES;
        [self bringSubviewToFront:self.removeBtn];
    }
    return self;
}


- (void)removeBtnAction {
    
    self.bankCardImageView.image = [UIImage imageNamed:@"ic_Bank card"];
    self.removeBtn.hidden = YES;
    self.hintLabel.hidden = NO;
    self.cameraImageView.hidden = NO;
    self.imageUrl = @"";
}



- (UIImageView *)bankCardImageView {
    
    if (!_bankCardImageView) {
        _bankCardImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_Bank card"]];
        [_bankCardImageView setContentMode:UIViewContentModeScaleAspectFit];
        
        [self addSubview:_bankCardImageView];
    }
    return _bankCardImageView;
}
- (UIImageView *)cameraImageView {
    
    if (!_cameraImageView) {
        _cameraImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic_photograph"]];
        [_cameraImageView setContentMode:UIViewContentModeScaleAspectFit];
        
        [self addSubview:_cameraImageView];
    }
    return _cameraImageView;
}
- (UILabel *)hintLabel {
    
    if (!_hintLabel) {
        _hintLabel = [[UILabel alloc] init];
        [_hintLabel setTextAlignment:NSTextAlignmentCenter];
        _hintLabel.textColor = HexColor(0x333333);
        _hintLabel.font = [UIFont systemFontOfSize:14];
        _hintLabel.text = @"拍摄银行卡正面";
        
        [self addSubview:_hintLabel];
    }
    return _hintLabel;
}

- (UIButton *)removeBtn {
    
    if (!_removeBtn) {
        _removeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_removeBtn setImage:[UIImage imageNamed:@"ic_del"] forState:UIControlStateNormal];
        [_removeBtn addTarget:self action:@selector(removeBtnAction) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:_removeBtn];
    }
    return _removeBtn;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
